{% extends "layout.twig" %}

{% block body %}
    <head>
        <meta name="viewport" content="width=device-width, initial-scale=1.0"/>
    </head>
    <header>
        <div class="">
            <div class="logo"></div>
        </div>
        <form method="POST" action="/api/auth/logout">
            <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
            <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
            <input class="button" type="submit" id="logout" value="Log out" />
        </form>
    </header>

    <div class="content">
        <h1>Nextcloud AIO v8.2.0</h1>

        {# Add 2nd tab warning #}
        <script type="text/javascript" src="second-tab-warning.js"></script>

        {% set isAnyRunning = false %}
        {% set isAnyRestarting = false %}
        {% set isWatchtowerRunning = false %}
        {% set isDomaincheckRunning = false %}
        {% set isBackupOrRestoreRunning = false %}
        {% set isApacheStarting = false %}
        {# Setting newMajorVersion to '' will hide corresponding options/elements, can be set to an integer like 26 in order to show corresponding elements. If set, also increase installLatestMajor in https://github.com/nextcloud/all-in-one/blob/main/php/src/Controller/DockerController.php #}
        {% set newMajorVersion = '' %}

        {% if is_backup_container_running == true %}
            {% if borg_backup_mode == 'backup' or borg_backup_mode == 'restore' %}
                {% set isBackupOrRestoreRunning = true %}
            {% endif %}
        {% endif %}

        {% for container in containers %}
            {% if container.GetDisplayName() != '' and class(container.GetRunningState()) == 'AIO\\Container\\State\\RunningState' %}
                {% set isAnyRunning = true %}
            {% endif %}
            {% if container.GetDisplayName() != '' and class(container.GetRestartingState()) == 'AIO\\Container\\State\\RestartingState' %}
                {% set isAnyRestarting = true %}
            {% endif %}
            {% if container.GetIdentifier() == 'nextcloud-aio-watchtower' and class(container.GetRunningState()) == 'AIO\\Container\\State\\RunningState' %}
                {% set isWatchtowerRunning = true %}
            {% endif %}
            {% if container.GetIdentifier() == 'nextcloud-aio-domaincheck' and class(container.GetRunningState()) == 'AIO\\Container\\State\\RunningState' %}
                {% set isDomaincheckRunning = true %}
            {% endif %}
            {% if container.GetIdentifier() == 'nextcloud-aio-apache' and class(container.GetStartingState()) == 'AIO\\Container\\State\\StartingState' %}
                {% set isApacheStarting = true %}
            {% endif %}
        {% endfor %}

        {% if is_daily_backup_running == true %}
            <span class="status running"></span> Daily backup currently running. (<a href="/api/docker/logs?id=nextcloud-aio-mastercontainer" target="_blank" rel="noopener">Logs</a>)<br /><br />
            {% if automatic_updates == true %}
                It will update your containers, the mastercontainer and on saturdays your Nextcloud apps if the backup is successful.<br /><br />
                {% if is_mastercontainer_update_available == true %}
                    Since the mastercontainer gets updated, it will restart the container which will make it unavailable for a moment. (<a href="/api/docker/logs?id=nextcloud-aio-watchtower" target="_blank" rel="noopener">Logs</a>)<br /><br />
                {% endif %}
            {% endif %}
            {% if has_update_available == false %}
                The whole process should not take more than a few minutes.<br /><br />
            {% elseif automatic_updates == true %}
                The whole process can take a while because your containers get updated.<br /><br />
            {% endif %}
            <a href="" class="button reload">Reload ↻</a><br/>
        {% elseif isWatchtowerRunning == true %}
            <span class="status running"></span> Mastercontainer update currently running. It will restart the mastercontainer soon which will make it unavailable for a moment. Please wait until that's done. (<a href="/api/docker/logs?id=nextcloud-aio-watchtower" target="_blank" rel="noopener">Logs</a>)<br /><br />
            <a href="" class="button reload">Reload ↻</a><br/>
        {% else %}
            {% if is_backup_container_running == false and domain == "" %}
                {% if isDomaincheckRunning == false %}
                    <h2>Domaincheck container is not running</h2>
                    This is not expected. Most likely this happened because port {{ apache_port }} is already in use on your server. You can check the mastercontainer logs and domaincheck container logs for further clues. You should be able to resolve this by adjusting the APACHE_PORT by following the <b><a href="https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md">reverse proxy documentation</a></b>. Advice: have a detailed look at the changed docker run command for AIO.
                {% elseif is_mastercontainer_update_available == true %}
                    <h2>Mastercontainer update</h2>
                    ⚠️ A mastercontainer update is available. Please click on the button below to update it. Afterwards, you will be able to proceed with the setup.<br><br>
                    <form method="POST" action="/api/docker/watchtower" class="xhr">
                        <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                        <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                        <input class="button" type="submit" value="Update mastercontainer" />
                    </form>
                {% else %}
                    {% if borg_backup_host_location == '' and borg_restore_password == '' %}
                        The official Nextcloud installation method. Nextcloud All-in-One provides easy deployment and maintenance with most features included in this one Nextcloud instance.<br><br>
                        You can either create a new AIO instance or restore a former AIO instance from backup. See the two sections below.<br><br>
                        {{ include('includes/aio-config.twig') }}
                        <h2>New AIO instance</h2>
                        {% if apache_port == '443' %}
                            AIO is currently in "normal mode" which means that it handles the TLS proxying itself. This also means that it cannot be installed behind a web server or reverse proxy (like Apache, Nginx, Cloudflare Tunnel and else). If you want to run AIO behind a web server or reverse proxy (like Apache, Nginx, Cloudflare Tunnel and else), see the <b><a href="https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md">reverse proxy documentation</a></b>. Advice: have a detailed look at the changed docker run command for AIO.<br><br>
                        {% else %}
                            AIO is currently in "reverse proxy mode" which means that it can be installed behind a web server or reverse proxy (like Apache, Nginx, Cloudflare Tunnel and else) and does not do the TLS proxying itself.<br><br>
                        {% endif %}
                        Please type in the domain into the input field below that will be used for Nextcloud in order to create a new AIO instance.<br><br />
                        {% if skip_domain_validation == true %}
                            <b>Please note:</b> The domain validation is disabled so any domain will be accepted here! So make sure that you do not make a typo here as you will not be able to change it afterwards!<br><br>
                        {% endif %}
                        <form method="POST" action="/api/configuration" class="xhr">
                            <input type="text" name="domain" value="{{ domain }}" placeholder="nextcloud.yourdomain.com"/>
                            <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                            <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                            <input class="button" type="submit" value="Submit domain" />
                        </form>
                        {% if skip_domain_validation == false %}
                            Make sure that this server is reachable on port 443 (port 443/tcp is open/forwarded in your firewall/router and 443/udp as well if you want to enable http3) and that you've correctly set up the DNS config for the domain that you enter (set the A record to your public ipv4-address and if you need ipv6, set the AAAA record to your public ipv6-address. A CNAME record if of course also possible). You should see hints on what went wrong if your domain does not get accepted in the top right corner.<br><br>
                            <details>
                                <summary>Click here for further hints</summary><br />
                                If you should not have a domain yet, you can get one for free e.g. from duckdns.org and others.<br><br>
                                If you have a dynamic public IP-address, you can use e.g. <a href="https://ddclient.net/">DDclient</a> with a compatible domain provider for DNS updates.<br /><br/>
                                If you only want to install AIO locally without exposing it to the public internet or if you cannot do so, feel free to follow <a href="https://github.com/nextcloud/all-in-one/blob/main/local-instance.md">this documentation</a>.<br><br>
                                If you should be using Cloudflare Proxy for your domain, make sure to disable the Proxy feature temporarily as it might block the domain validation attempts.<br /><br/>
                                {% if apache_port != '443' %}
                                    If you run into issues getting your domain accepted, see <a href="https://github.com/nextcloud/all-in-one/blob/main/reverse-proxy.md#6-how-to-debug-things">these steps</a> for how to debug things. <br /><br/>
                                {% endif %}
                                <b>Hint:</b> If the domain validation fails but you are completely sure that you've configured everything correctly, you may skip the domain validation by following <a href="https://github.com/nextcloud/all-in-one#how-to-skip-the-domain-validation">this documentation</a>.<br />
                            </details>
                        {% endif %}

                        <h2>Restore former AIO instance from backup</h2>
                        You can alternatively restore a former AIO instance from backup.<br><br>
                    {% endif %}

                    {% if is_instance_restore_attempt == false %}
                        {% if borg_backup_host_location != '' and borg_restore_password != '' %}
                            {% if borg_backup_mode in ['test', 'check'] %}
                                {% if backup_exit_code > 0 %}
                                    <span class="status error"></span> Last {{ borg_backup_mode }} failed! (<a href="/api/docker/logs?id=nextcloud-aio-borgbackup" target="_blank" rel="noopener">Logs</a>)<br /><br />
                                    {% if borg_backup_mode == 'test' %}
                                        Please adjust the path and/or the password in order to make it work!<br><br>
                                    {% elseif borg_backup_mode == 'check' %}
                                        The backup archive seems to be corrupt. Please try to use a different intact backup archive or try to fix it by following <a href="https://borgbackup.readthedocs.io/en/stable/faq.html#i-get-an-integrityerror-or-similar-what-now"><b>this documentation</b></a><br><br>
                                        <details>
                                            <summary>Reveal repair option</summary><br />
                                            Below is the option to repair the integrity of your backup. <b>Please note:</b> Please only use this after you have read the documentation above! (It will run the command 'borg check --repair' for you.)<br><br>
                                            <form method="POST" action="/api/docker/backup-check-repair" class="xhr">
                                                <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                                <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                                <input class="button" type="submit" value="Check and repair backup integrity" onclick="return confirm('Check and repair backup integrity? Are you sure that you want to check and repair the backup integrity? This should only be done after reading the mentioned documentation.')"/><br/>
                                            </form><br />
                                        </details><br />
                                    {% endif %}
                                {% elseif backup_exit_code == 0 %}
                                    <span class="status success"></span> Last {{ borg_backup_mode }} successful! (<a href="/api/docker/logs?id=nextcloud-aio-borgbackup" target="_blank" rel="noopener">Logs</a>)<br /><br />
                                    {% if borg_backup_mode == 'test' %}
                                        Feel free to check the integrity of the backup archive below before starting the restore process in order to make double-sure that the restore will work. This can take a long time though depending on the size of the backup archive and is thus not required.<br><br>
                                        <form method="POST" action="/api/docker/backup-check" class="xhr">
                                            <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                            <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                            <input class="button" type="submit" value="Check backup integrity"/><br/>
                                        </form>
                                    {% endif %}
                                    Choose the backup that you want to restore and click on the button below to restore the selected backup. This will restore the whole AIO instance from backup. Please note that the current AIO password will be kept and the previous AIO password will not be restored from backup!<br><br>
                                    <form method="POST" action="/api/docker/restore" class="xhr" id="restore_selection">
                                        <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                        <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                        <select id="selected_restore_time" name="selected_restore_time" form="restore_selection">
                                            {% for restore_time in backup_times %}
                                                <option value="{{ restore_time }}">{{ restore_time }} UTC</option>
                                            {% endfor %}
                                        </select>
                                        <input class="button" type="submit" value="Restore selected backup"/>
                                    </form>
                                {% endif %}
                            {% elseif borg_backup_mode == 'restore' %}
                                {% if backup_exit_code > 0 %}
                                    <span class="status error"></span> Last restore failed! (<a href="/api/docker/logs?id=nextcloud-aio-borgbackup" target="_blank" rel="noopener">Logs</a>)<br /><br />
                                    Somehow the restore failed which is unexpected! Please adjust the path and password, test it and try to restore again!
                                {% endif %}
                            {% endif %}
                        {% endif %}

                        {% if borg_backup_host_location == '' or borg_restore_password == '' or borg_backup_mode not in ['test', 'check', ''] or backup_exit_code > 0 %}
                            Please enter the location of the backup archive on your host and the password of the backup archive below:<br><br>
                            <form method="POST" action="/api/configuration" class="xhr">
                                <input type="text" name="borg_restore_host_location" value="{{borg_backup_host_location}}" placeholder="/mnt/backup"/>
                                <input type="text" name="borg_restore_password" value="{{borg_restore_password}}" placeholder="enter the borg password"/>
                                <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                <input class="button" type="submit" value="Submit location and password" />
                            </form>
                            {{ include('includes/backup-dirs.twig') }}
                            ⚠️ Please note that the backup archive must be located in a subfolder of the folder that you enter here and the subfolder which contains the archive must be named 'borg'. Otherwise will the backup container not find the backup archive!<br><br>
                        {% endif %}
                    {% else %}
                        <b>Everything set!</b> Click on the button below to test the path and password:<br/><br/>
                        <form method="POST" action="/api/docker/backup-test" class="xhr">
                            <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                            <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                            <input class="button" type="submit" value="Test path and password"/><br/>
                        </form>
                    {% endif %}
                {% endif %}
            {% endif %}

            {% if was_start_button_clicked == true %}
                {% if current_channel starts with 'latest' or current_channel starts with 'beta' or current_channel starts with 'develop' %}
                    You are running the <a href="https://github.com/nextcloud/all-in-one#how-to-switch-the-channel"><b>{{ current_channel }}</b></a> channel. (<a href="/api/docker/logs?id=nextcloud-aio-mastercontainer" target="_blank" rel="noopener">Logs</a>)<br><br>
                {% else %}
                    No channel was found. This means that AIO is not able to update itself and its component and will also not be able to report about updates. Updates need to be done externally.
                {% endif %}
            {% endif %}

            {% if is_backup_container_running == true %}
                <span class="status running"></span> Backup container is currently running. (<a href="/api/docker/logs?id=nextcloud-aio-borgbackup" target="_blank" rel="noopener">Logs</a>)<br /><br />
                <a href="" class="button reload">Reload ↻</a><br/><br>
            {% endif %}

            {% if domain != "" %}
                {% if isAnyRunning == true %}
                    {% if isApacheStarting != true %}
                        {% if borg_backup_host_location != '' %}
                            <details>
                            <summary>Click here to reveal the initial Nextcloud credentials</summary><br />
                        {% endif %}
                                Initial Nextcloud username: <b>admin</b><br />
                                Initial Nextcloud password: 
                        {% if borg_backup_host_location != '' %}
                            {# nextcloud_password needs to be duplicated due to a bug in Firefox. See https://github.com/nextcloud/all-in-one/issues/638. #}
                            <b>{{ nextcloud_password }}</b><br /></details><br />
                        {% else %}
                            <b>{{ nextcloud_password }}</b><br><br>
                        {% endif %}
                        <a href="https://{{ domain }}" class="button" target="_blank" rel="noopener">Open your Nextcloud ↗</a><br/><br>
                        {% if borg_backup_host_location == '' %}
                            If your Nextcloud does not open when clicking the button above, see <b><a href="https://github.com/nextcloud/all-in-one/discussions/2105">this documentation</a></b><br><br>
                        {% endif %}
                    {% else %}
                        {% if isAnyRestarting == false %}
                            <span class="status running"></span> Containers are currently starting.<br /><br />
                            <a href="" class="button reload">Reload ↻</a><br/><br>
                        {% else %}
                            It seems like at least one container is currently restarting which means it is not able to start correctly.<br><br>
                            To break out this endless loop, you can stop the containers below and investigate the issue by having a look at the container logs before starting them again.<br><br>
                            <form method="POST" action="/api/docker/stop" class="xhr">
                                <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                <input class="button" type="submit" value="Stop containers" />
                            </form>
                        {% endif %}
                    {% endif %}
                {% endif %}

                {% if isApacheStarting == false and is_backup_container_running == false %}
                    {{ include('includes/aio-config.twig') }}
                {% endif %}

                {% if was_start_button_clicked == true %}
                    <h2>Containers</h2>
                    <ul>
                        {# @var containers \AIO\Container\Container[] #}
                        {% for container in containers %}
                            {% if container.GetDisplayName() != '' %}
                                <li>
                                    {% if class(container.GetStartingState()) == 'AIO\\Container\\State\\StartingState' %}
                                        <span class="status running"></span>
                                        <span>{{ container.GetDisplayName() }} (<a href="/api/docker/logs?id={{ container.GetIdentifier() }}" target="_blank" rel="noopener">Starting</a>)
                                        {% if container.GetDocumentation() != '' %}
                                            (<a href="{{ container.GetDocumentation() }}">docs</a>)
                                        {% endif %}
                                        </span>
                                    {% elseif class(container.GetRunningState()) == 'AIO\\Container\\State\\RunningState' %}
                                        <span class="status success"></span>
                                        <span>{{ container.GetDisplayName() }} (<a href="/api/docker/logs?id={{ container.GetIdentifier() }}" target="_blank" rel="noopener">Running</a>)
                                        {% if container.GetDocumentation() != '' %}
                                            (<a href="{{ container.GetDocumentation() }}">docs</a>)
                                        {% endif %}
                                        </span>
                                    {% else %}
                                        <span class="status error"></span>
                                        <span>{{ container.GetDisplayName() }} (<a href="/api/docker/logs?id={{ container.GetIdentifier() }}" target="_blank" rel="noopener">Stopped</a>)
                                        {% if container.GetDocumentation() != '' %}
                                            (<a href="{{ container.GetDocumentation() }}">docs</a>)
                                        {% endif %}
                                        </span>
                                    {% endif %}
                                </li>
                            {% endif %}
                        {% endfor %}
                    </ul>

                    {% if has_update_available == true %}
                        {% if is_mastercontainer_update_available == false %}
                            ⚠️ Container updates are available. Click on <b>Stop containers</b> and <b>Start and update containers</b> to update them. You should consider creating a backup first.<br><br>
                        {% endif %}
                    {% else %}
                        {% if is_mastercontainer_update_available == false %}
                            Your containers are up-to-date.<br><br>
                            {% if newMajorVersion != '' and isAnyRunning == true and isApacheStarting != true %}
                                <details>
                                <summary>Note about <b>Nextcloud {{ newMajorVersion }}</b></summary><br>
                                    If you haven't upgraded to Nextcloud {{ newMajorVersion }} yet and want to do that now, feel free to follow <b><a href="https://github.com/nextcloud/all-in-one/discussions/2692">this documentation</a></b><br/>
                                </details><br>
                            {% endif %}
                        {% endif %}
                    {% endif %}
                {% endif %}

                {% if isAnyRunning == true %}
                    {% if isApacheStarting != true %}
                        {% if is_mastercontainer_update_available == true %}
                            ⚠️ A mastercontainer update is available. Please click on the button below to stop your containers in order to be able to update the mastercontainer.<br /><br />
                            {% if current_channel starts with 'latest' %}
                                You can find the changelog <a href="https://github.com/nextcloud/all-in-one/releases/latest"><b>here</b></a><br><br>
                            {% elseif current_channel starts with 'beta' %}
                                You can find the changelog <a href="https://github.com/nextcloud/all-in-one/releases"><b>here</b></a><br><br>
                            {% elseif current_channel starts with 'develop' %}
                                You can find all changes <a href="https://github.com/nextcloud-releases/all-in-one/commits/main"><b>here</b></a><br><br>
                            {% endif %}
                        {% endif %}
                        <form method="POST" action="/api/docker/stop" class="xhr">
                            <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                            <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                            <input class="button" type="submit" value="Stop containers" />
                        </form>
                    {% endif %}
                {% else %}
                    {% if isBackupOrRestoreRunning == true %}
                        Restore or Backup currently running. Cannot start the containers until that's done.<br /><br />
                    {% else %}
                        {% if was_start_button_clicked == false %}
                            <br>Clicking on the button below will download all docker containers and start them. This can take a lot of time depending on your internet connection. Since the overall size is a few GB, this will take around 5-10 min or more. So be aware and patient!<br><br>
                        {% endif %}
                        {% if is_mastercontainer_update_available == true %}
                            ⚠️ A mastercontainer update is available. Please click on the button below to update it.<br><br>
                            <form method="POST" action="/api/docker/watchtower" class="xhr">
                                <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                <input class="button" type="submit" value="Update mastercontainer" />
                            </form>
                        {% else %}
                            {% if was_start_button_clicked == false %}
                                <form method="POST" action="/api/docker/start" class="xhr">
                                    <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                    <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                    {% if newMajorVersion != '' %}
                                        <input type="checkbox" id="install_latest_major" name="install_latest_major"><label for="install_latest_major">Install Nextcloud {{ newMajorVersion }} (if unchecked, Nextcloud {{ newMajorVersion - 1 }} will get installed)</label><br>
                                    {% endif %}
                                    <input class="button" type="submit" value="Download and start containers" />
                                </form>
                            {% elseif has_update_available == false %}
                                <form method="POST" action="/api/docker/start" class="xhr">
                                    <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                    <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                    <input class="button" type="submit" value="Start containers" />
                                </form>
                            {% else %}
                                <form method="POST" action="/api/docker/start" class="xhr">
                                    <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                    <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                    <input class="button " type="submit" value="Start and update containers" onclick="return confirm('Start and update containers? You should consider creating a backup first.')" />
                                </form>
                            {% endif %}
                        {% endif %}
                    {% endif %}
                {% endif %}

                {% if was_start_button_clicked == true %}

                    {% if is_backup_section_enabled == false %}
                        <h2>Backup and restore</h2>
                        The backup section is disabled via environmental variable.<br><br>
                    {% else %}
                        {% if is_backup_container_running == false and borg_backup_host_location == "" and isApacheStarting != true %}
                            <h2>Backup and restore</h2>
                            Please type in the directory where backups will get created on the host system below. In best case make sure that you choose a location on a separate drive and not on your root drive.<br><br>
                            <form method="POST" action="/api/configuration" class="xhr">
                                <input type="text" name="borg_backup_host_location" placeholder="/mnt/backup"/>
                                <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                <input class="button" type="submit" value="Submit backup location" />
                            </form>
                            {{ include('includes/backup-dirs.twig') }}
                        {% endif %}
                    {% endif %}

                    {% if is_backup_section_enabled == true %}

                        {% if borg_backup_host_location != "" %}
                            {% if is_backup_container_running == false %}
                                <h2>Backup and restore</h2>
                                {% if backup_exit_code > 0 %}
                                    <span class="status error"></span> Last {{ borg_backup_mode }} failed! (<a href="/api/docker/logs?id=nextcloud-aio-borgbackup" target="_blank" rel="noopener">Logs</a>)<br /><br />
                                    {% if borg_backup_mode == "check" %}
                                        The backup check was not successful which might points towards a corrupt archive (look at the logs). If that should be the case, you can try to fix it by following <a href="https://borgbackup.readthedocs.io/en/stable/faq.html#i-get-an-integrityerror-or-similar-what-now"><b>this documentation</b></a><br /><br />
                                        <details>
                                            <summary>Reveal repair option</summary><br />
                                            Below is the option to repair the integrity of your backup. <b>Please note:</b> Please only use this after you have read the documentation above! (It will run the command 'borg check --repair' for you.)<br><br>
                                            <form method="POST" action="/api/docker/backup-check-repair" class="xhr">
                                                <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                                <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                                <input class="button" type="submit" value="Check and repair backup integrity" onclick="return confirm('Check and repair backup integrity? Are you sure that you want to check and repair the backup integrity? This should only be done after reading the mentioned documentation.')"/><br/>
                                            </form><br />
                                        </details><br />
                                    {% endif %}
                                    {% if has_backup_run_once == false %}
                                        You may change the backup path again since the initial backup was not successful. After submitting the new value, you need to click on <b>Create Backup</b> for testing the new value.<br /><br />
                                        <form method="POST" action="/api/configuration" class="xhr">
                                            <input type="text" value="{{borg_backup_host_location}}" name="borg_backup_host_location" placeholder="/mnt/backup" />
                                            <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                            <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                            <input class="button" type="submit" value="Set backup location again" />
                                        </form>
                                    {% endif %}
                                {% elseif backup_exit_code == 0 %}
                                    {% if borg_backup_mode == "backup" %}
                                        <span class="status success"></span> Last {{ borg_backup_mode }} successful on {{ last_backup_time }} UTC! (<a href="/api/docker/logs?id=nextcloud-aio-borgbackup" target="_blank" rel="noopener">Logs</a>)<br /><br />
                                    {% else %}
                                        <span class="status success"></span> Last {{ borg_backup_mode }} successful! (<a href="/api/docker/logs?id=nextcloud-aio-borgbackup" target="_blank" rel="noopener">Logs</a>)<br /><br />
                                    {% endif %}
                                {% endif %}
                            {% endif %}

                            {% if is_backup_container_running == false and isApacheStarting == false %}
                                {% if has_backup_run_once == true %}
                                    <details>
                                    <summary>Click here to reveal all backup options (it also includes an option for automatic updates)</summary><br />
                                {% endif %}
                                <h3>Backup information</h3>
                                This is your encryption password for backups: <b>{{ borgbackup_password }}</b><br /><br/>
                                Please save it at a safe place since you won't be able to restore from backup if you lose this password! <br /><br/>
                                Backed up will get all important data of your Nextcloud AIO instance like the database, your files and configuration files of the mastercontainer and else. <br /><br/>
                                The backup itself uses a tool that is called <a href="https://github.com/borgbackup/borg#what-is-borgbackup"><b>BorgBackup</b></a> which is a well-known server backup tool that efficiently backs up your files and encrypts them on the fly. <br /><br/>
                                By using this tool, backups are incremental, differential, compressed and encrypted – so only the first backup will take a while. Further backups should be fast as only changes are taken into account.<br /><br/>
                                Backups get created in the following directory on the host: <b>{{ borg_backup_host_location }}/borg</b> <br /><br/>
                                Be aware that this solution does not back up files and folders that are mounted into Nextcloud using the external storage app - but you can add further Docker volumes and host paths that you want to back up after the initial backup is done.<br><br>
                                Regarding backup retention, see <b><a href="https://github.com/nextcloud/all-in-one#how-to-adjust-borgs-retention-policy">this</a></b>.<br><br>
                                Daily backups can get enabled after the initial backup is done. Enabling this also allows to enable an option that allows to update all containers, Nextcloud and its apps automatically.<br><br>
                                For further documentation and options on this backup solution refer to <b><a href="https://github.com/nextcloud/all-in-one#backup-solution">this section</a></b> and below.<br>

                                {% if isApacheStarting != true %}
                                    <h3>Backup creation</h3>
                                    Clicking on the button below will create a backup.<br><br/>
                                    <form method="POST" action="/api/docker/backup" class="xhr">
                                        <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                        <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                        <input class="button" type="submit" value="Create backup" onclick="return confirm('Create backup? Are you sure that you want to create a backup? This will stop all running containers and create the backup.')" />
                                    </form>

                                    {% if has_backup_run_once == false %}
                                        <h3>Reset backup host location</h3>
                                        If the configured backup host location <b>{{ borg_backup_host_location }}</b> is wrong, you can reset it by clicking on the button below.<br><br/>
                                        <form method="POST" action="/api/configuration" class="xhr">
                                            <input type="hidden" name="delete_borg_backup_host_location" value="yes"/>
                                            <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                            <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                            <input class="button" type="submit" value="Reset backup location" />
                                        </form>
                                    {% endif %}

                                    {% if has_backup_run_once == true %}
                                        <h3>Backup check</h3>
                                        Click on the button below to perform a backup integrity check. This is an option that verifies that your backup is intact but it shouldn't be needed in most situations.<br><br/>
                                        <form method="POST" action="/api/docker/backup-check" class="xhr">
                                            <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                            <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                            <input class="button" type="submit" value="Check backup integrity" onclick="return confirm('Check backup integrity? Are you sure that you want to check the backup? This can take a long time depending on the size of your backup.')" /><br/>
                                        </form>

                                        <h3>Backup restore</h3>
                                        Choose the backup that you want to restore and click on the button below to restore the selected backup. This will overwrite all your files with the state of the backup so you should consider creating a backup first. It also makes sense to run an integrity check before restoring your files but is not mandatory since it shouldn't be needed in most situations. Please note that this will not restore additionally chosen backup directories! The restore process should be pretty fast as rsync is used to restore the chosen backup which only transfers changed files and deletes additional ones.<br><br>
                                        <form method="POST" action="/api/docker/restore" class="xhr" id="restore_selection">
                                            <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                            <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                            <select id="selected_restore_time" name="selected_restore_time" form="restore_selection">
                                                {% for restore_time in backup_times %}
                                                    <option value="{{ restore_time }}">{{ restore_time }} UTC</option>
                                                {% endfor %}
                                            </select>
                                            <input class="button" type="submit" value="Restore selected backup" onclick="return confirm('Restore the selected backup? Are you sure that you want to restore the selected backup? This will stop all running containers and restore the selected backup. It is recommended to create a backup first. You might also want to check the backup integrity.')" />
                                        </form>

                                        <h3>Daily backup and automatic updates</h3>
                                        {% if daily_backup_time == "" %}
                                            By entering a time below, you can enable daily backups. It will create them at the entered time in 24h format. E.g. <b>04:00</b> will create backups at 4 am UTC and <b>16:00</b> at 4 pm UTC. For creating the backup, it will stop the containers and start them back up after the backup is done.<br><br/>
                                            <form method="POST" action="/api/configuration" class="xhr">
                                                <input type="text" name="daily_backup_time" value="04:00" placeholder="04:00"/>
                                                <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                                <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                                <input class="button" type="submit" value="Submit backup time" /><br>
                                                <input type="checkbox" id="automatic_updates" name="automatic_updates" checked="checked"><label for="automatic_updates">Automatically update all containers, the mastercontainer and on saturdays your Nextcloud apps</label><br>
                                                <input type="checkbox" id="success_notification" name="success_notification" checked="checked"><label for="success_notification">Send notifications about successful backups (notifications about unsuccessful backups will always be sent)</label><br>
                                            </form>
                                        {% else %}
                                            Daily backups will be created at <b>{{ daily_backup_time }} UTC</b> which includes a notification about the result of the backup.
                                            {% if automatic_updates == true %}
                                                Also your containers, the mastercontainer and on saturdays your Nextcloud apps will be automatically updated. 
                                            {% endif %}
                                            To change your backup time, first disable Daily Backups and then re-enable them with your new backup time.<br><br/>
                                            <form method="POST" action="/api/configuration" class="xhr">
                                                <input type="hidden" name="delete_daily_backup_time" value="yes"/>
                                                <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                                <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                                <input class="button" type="submit" value="Disable or change daily backups" />
                                            </form>
                                        {% endif %}

                                        <h3>Back up additional directories and docker volumes of your host</h3>
                                        Below, you can enter directories and docker volumes of your host that will backed up additionally into the same borg backup archive.<br><br>
                                        <form method="POST" action="/api/configuration" class="xhr">
                                            <textarea id="additional_backup_directories" name="additional_backup_directories" rows="4" cols="50" placeholder="/directory/on/the/host&#10;my_custom_docker_volume">{{ additional_backup_directories }}</textarea>
                                            <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                            <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                            <input class="button" type="submit" value="Submit additional backup locations" /><br>
                                        </form>
                                        Each line and entry needs to start with a slash or letter/digit. Allowed are only <b>a-z</b>, <b>A-Z</b>, <b>.</b>, <b>0-9</b>, <b>_</b>, <b>-</b>, and <b>/</b>. If the entry begins with a letter/digit are slashes not supported. Two valid entries are <b>/directory/on/the/host</b> and <b>my_custom_docker_volume</b>. You need to make sure yourself that all given directories exist. Otherwise the backup container will fail starting!<br><br/>
                                        Make sure to specify all storages that you want to back up separately since storages will not be mounted recursively. E.g. providing <b>/</b> as additional backup directory will only back up files and folders that are stored on the root partition and not on the EFI partition or any other. Excluded by the backup will be caches and a few other directories. You should make sure to stop all services before the backup can run correctly if you want to back up the root partition. For automating this see <a href="https://github.com/nextcloud/all-in-one#how-to-stopstartupdate-containers-or-trigger-the-daily-backup-from-a-script-externally">this documentation</a><br><br/>
                                        Please note that the chosen directories/volumes will not be restored when you restore your instance, so this would need to be done manually. <br><br>
                                        {% if additional_backup_directories != "" %}
                                            This option is currently set. You can disable it again by clearing the field and submitting your changes.<br><br>
                                        {% endif %}
                                    {% endif %}
                                {% endif %}
                                {% if has_backup_run_once == false %}
                                    <br />
                                {% else %}
                                    </details>
                                {% endif %}
                            {% endif %}
                        {% endif %}
                    {% endif %}

                    {% if is_backup_container_running == false %}
                        {% if isApacheStarting == false %} 
                            <h2>AIO password change</h2>
                            <details>
                                <summary>Click here to change your AIO password</summary><br />
                                You can change your AIO password below:<br><br />
                                <form method="POST" action="/api/configuration" class="xhr">
                                    <input type="password" autocomplete="current-password" name="current-master-password" placeholder="Your current AIO password" id="current-master-password" oninput="showPassword('current-master-password')">
                                    <input type="password" autocomplete="new-password" name="new-master-password" placeholder="Your new AIO password" id="new-master-password" oninput="showPassword('new-master-password')">
                                    <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                    <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                    <input class="button" type="submit" value="Submit password change" />
                                </form>
                                The new password needs to be at least 24 characters long. Allowed characters are the <a href="https://en.wikipedia.org/wiki/Latin_alphabet#/media/File:Abecedarium.png"><b>latin characters</b></a> <b>a-z</b>, <b>A-Z</b>, <b>0-9</b> and <b>spaces</b>.<br>
                            </details>
                        {% endif %}
                    {% endif %}
                {% endif %}
                {% if is_backup_container_running == false %}
                    <h2>Optional containers</h2>
                    In this section you can enable or disable optional containers. There are further community containers available that are not listed below. See <b><a href="https://github.com/nextcloud/all-in-one/tree/main/community-containers#community-containers">this documentation</a></b> how to add them.<br><br>
                    {% if isAnyRunning == true %}
                        <b>Please note:</b> You can enable or disable them when your containers are stopped.<br><br>
                    {% else %}
                        <b>Please note:</b> Make sure to save your changes by clicking on the button <b>Save changes</b> that is positioned below the list of optional containers. The changes will not be auto-saved.<br><br>
                    {% endif %}
                    <form id="options-form" method="POST" action="/api/configuration" class="xhr">
                        <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                        <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                        <input type="hidden" name="options-form" value="options-form">
                        {% if is_clamav_enabled == true %}
                            <input type="checkbox" id="clamav" name="clamav" checked="checked"><label for="clamav">ClamAV (Antivirus backend for Nextcloud, only supported on x64, needs ~1GB additional RAM)</label><br><br>
                        {% else %}
                            <input type="checkbox" id="clamav" name="clamav"><label for="clamav">ClamAV (Antivirus backend for Nextcloud, only supported on x64, needs ~1GB additional RAM)</label><br><br>
                        {% endif %}
                        {% if is_collabora_enabled == true %}
                            <input type="checkbox" id="collabora" name="collabora" checked="checked"><label for="collabora">Collabora (Nextcloud Office)</label><br>
                        {% else %}
                            <input type="checkbox" id="collabora" name="collabora"><label for="collabora">Collabora (Nextcloud Office)</label><br>
                        {% endif %}
                        {% if is_fulltextsearch_enabled == true %}
                            <input type="checkbox" id="fulltextsearch" name="fulltextsearch" checked="checked"><label for="fulltextsearch">Fulltextsearch (needs ~1GB additional RAM)</label><br>
                        {% else %}
                            <input type="checkbox" id="fulltextsearch" name="fulltextsearch"><label for="fulltextsearch">Fulltextsearch (needs ~1GB additional RAM. <b>Please note:</b> the initial indexing can take a long time during which Nextcloud will be unavailable)</label><br><br>
                        {% endif %}
                        {% if is_imaginary_enabled == true %}
                            <input type="checkbox" id="imaginary" name="imaginary" checked="checked"><label for="imaginary">Imaginary (for previews of heic, heif, illustrator, pdf, svg, tiff and webp. Imaginary is currently <a href="https://github.com/nextcloud/server/issues/34262">incompatible with server-side-encryption</a>)</label><br><br>
                        {% else %}
                            <input type="checkbox" id="imaginary" name="imaginary"><label for="imaginary">Imaginary (for previews of heic, heif, illustrator, pdf, svg, tiff and webp. Imaginary is currently <a href="https://github.com/nextcloud/server/issues/34262">incompatible with server-side-encryption</a>)</label><br><br>
                        {% endif %}
                        {% if is_talk_enabled == true %}
                            <input type="checkbox" id="talk" name="talk" checked="checked"><label for="talk">Nextcloud Talk (needs ports {{ talk_port }}/TCP and {{ talk_port }}/UDP open/forwarded in your firewall/router)</label><br><br>
                        {% else %}
                            <input type="checkbox" id="talk" name="talk"><label for="talk">Nextcloud Talk (needs ports {{ talk_port }}/TCP and {{ talk_port }}/UDP open/forwarded in your firewall/router)</label><br><br>
                        {% endif %}
                        {% if is_talk_recording_enabled == true %}
                            <input type="checkbox" id="talk-recording" name="talk-recording" checked="checked"><label for="talk-recording">Nextcloud Talk Recording-server (needs Nextcloud Talk being enabled and ~1GB additional RAM and ~2 additional vCPUs)</label><br><br>
                        {% else %}
                            <input type="checkbox" id="talk-recording" name="talk-recording"><label for="talk-recording">Nextcloud Talk Recording-server (needs Nextcloud Talk being enabled and ~1GB additional RAM ~2 additional vCPUs)</label><br><br>
                        {% endif %}
                        {% if is_onlyoffice_enabled == true %}
                            <input type="checkbox" id="onlyoffice" name="onlyoffice" checked="checked"><label for="onlyoffice">OnlyOffice</label><br>
                        {% else %}
                            {#<input type="checkbox" id="onlyoffice" name="onlyoffice"><label for="onlyoffice">OnlyOffice</label><br>#}
                        {% endif %}
                        {% if is_docker_socket_proxy_enabled == true %}
                            <input type="checkbox" id="docker-socket-proxy" name="docker-socket-proxy" checked="checked"><label for="docker-socket-proxy">Docker Socket Proxy (needed for <a href="https://github.com/cloud-py-api/app_api#nextcloud-appapi">Nextcloud App API</a>)</label><br><br>
                        {% else %}
                            <input type="checkbox" id="docker-socket-proxy" name="docker-socket-proxy"><label for="docker-socket-proxy">Docker Socket Proxy (needed for <a href="https://github.com/cloud-py-api/app_api#nextcloud-appapi">Nextcloud App API</a>)</label><br><br>
                        {% endif %}
                        <input id="options-form-submit" class="button" type="submit" value="Save changes" />
                        <script type="text/javascript" src="options-form-submit.js"></script>
                    </form>
                    <b>Minimal system requirements:</b> When any optional container is enabled, at least 2GB RAM, a dual-core CPU and 40GB system storage are required. When enabling ClamAV,  Nextcloud Talk Recording-server or Fulltextsearch, at least 3GB RAM are required. For Talk Recording-server additional 2 vCPUs are required. When enabling everything, at least 5GB RAM and a quad-core CPU are required. Recommended are at least 1GB more RAM than the minimal requirement. For further advices and recommendations see <b><a href="https://github.com/nextcloud/all-in-one/discussions/1335">this documentation</a></b><br>
                    {% if isAnyRunning == true or is_x64_platform == false %}
                        <script type="text/javascript" src="disable-clamav.js"></script>
                    {% endif %}
                    {% if isAnyRunning == true %}
                        <script type="text/javascript" src="disable-docker-socket-proxy.js"></script>
                        <script type="text/javascript" src="disable-talk.js"></script>
                        <script type="text/javascript" src="disable-collabora.js"></script>
                        <script type="text/javascript" src="disable-onlyoffice.js"></script>
                        <script type="text/javascript" src="disable-imaginary.js"></script>
                        <script type="text/javascript" src="disable-fulltextsearch.js"></script>
                        <script type="text/javascript" src="disable-talk-recording.js"></script>
                    {% endif %}

                    {% if is_collabora_enabled == true and isAnyRunning == false and was_start_button_clicked == true %}
                        <h3>Collabora dictionaries</h3>

                        {% if collabora_dictionaries == "" %}
                            In order to get the correct dictionaries in Collabora, you may configure the dictionaries below:<br><br>
                            <form method="POST" action="/api/configuration" class="xhr">
                                <input type="text" name="collabora_dictionaries" placeholder="de_DE en_GB en_US es_ES fr_FR it nl pt_BR pt_PT ru" />
                                <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                <input class="button" type="submit" value="Submit collabora dictionaries" />
                            </form>
                            You need to make sure that the dictionaries that you enter are valid. An example is <b>de_DE en_GB en_US es_ES fr_FR it nl pt_BR pt_PT ru</b>.<br><br>
                        {% else %}
                            The dictionaries for Collabora are currently set to <b>{{ collabora_dictionaries }}</b>. You can reset them again by clicking on the button below.<br><br/>
                            <form method="POST" action="/api/configuration" class="xhr">
                                <input type="hidden" name="delete_collabora_dictionaries" value="yes"/>
                                <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                <input class="button" type="submit" value="Reset collabora dictionaries" />
                            </form>
                        {% endif %}
                    {% endif %}

                    <h2>Timezone change</h2>
                    {% if isAnyRunning == true %}
                        {% if timezone != "" %}
                            The timezone for Nextcloud is currently set to <b>{{ timezone }}</b>.<br><br>
                        {% endif %}
                        <b>Please note:</b> You can change the timezone when your containers are stopped.<br><br>
                    {% else %}
                        {% if timezone == "" %}
                            In order to get the correct time values for certain Nextcloud features, it makes sense to set the timezone for Nextcloud to the one that your users mainly use. Please note that this setting does not apply to the mastercontainer and any backup option.<br><br>
                            You can configure the timezone for Nextcloud below:<br><br>
                            <form method="POST" action="/api/configuration" class="xhr">
                                <input type="text" name="timezone" placeholder="Europe/Berlin" />
                                <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                <input class="button" type="submit" value="Submit timezone" onclick="return confirm('Are you sure that this is a valid timezone? Please double check by following the wikipedia article and checking the correct column since if not, it will break the startup since the database will not get correctly initialized and you will end in a startup loop.')" />
                            </form>
                            You need to make sure that the timezone that you enter is valid. An example is <b>Europe/Berlin</b>. You can get valid values by looking at the 'TZ identifier' column of this list: <a href="https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List"><b>click here</b></a>. The default is <b>Etc/UTC</b> if nothing is entered.<br><br>
                        {% else %}
                            The timezone for Nextcloud is currently set to <b>{{ timezone }}</b>. You can reset the timezone again by clicking on the button below.<br><br/>
                            <form method="POST" action="/api/configuration" class="xhr">
                                <input type="hidden" name="delete_timezone" value="yes"/>
                                <input type="hidden" name="{{csrf.keys.name}}" value="{{csrf.name}}">
                                <input type="hidden" name="{{csrf.keys.value}}" value="{{csrf.value}}">
                                <input class="button" type="submit" value="Reset the timezone" />
                            </form>
                        {% endif %}
                    {% endif %}
                {% endif %}
            {% endif %}
        {% endif %}

    {% if isApacheStarting == true or is_backup_container_running == true or isWatchtowerRunning == true or is_daily_backup_running == true %}
        <script type="text/javascript" src="automatic_reload.js"></script>
    {% else %}
        <script type="text/javascript" src="before-unload.js"></script>
    {% endif %}

    </div>
    <div id="overlay">
        <div class="loader"></div>
    </div>
{% endblock %}
